/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Screen;


import ClassFrame.Button;
import ClassFrame.InputKey;
import ClassFrame.JFont;
import ClassFrame.Player;
import ClassFrame.Resource;
import GamePlay.CanvasGame;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author QuyetNM1
 */
public class Score extends IScreen{
    public Vector v = null;
    private JFont font;
    
    private Button buttBack;
    
    public Score(CanvasGame _canvas) {
        super(_canvas);
        canvas.getRMS().open();
        v = canvas.getRMS().read();
        canvas.getRMS().close();
        
    }
    
    public void initComponents(){
        buttBack = new Button("Quay lại", Resource.IMG_BTN_LT, 155, 285);
        
    }

    public void load_screen() {
        canvas.getResource().loadArray(Resource.highScoreArrayImages);
    }

    public void un_load_screen() {
        canvas.getResource().unLoadArray(Resource.highScoreArrayImages);
    }

    public void keyEvent(int keycode, int event){
        if(event == InputKey.KEY_EVENT_DOWN){
            if(keycode == InputKey.KEY_RIGHT_SOFTKEY){
                canvas.setScreen( new Menu(canvas));
                canvas.getResource().playSound(Resource.SOUND_BUTTON, 1);
            }
        }
    }

    public void pointerEvent(int x, int y, int event) {
        switch(event){
             case InputKey.POINTER_EVENT_DOWN:
                 if(canvas.checkButton(x, y, buttBack)){
                    buttBack.setState(Button.HOLD_CLICK);
                    canvas.getResource().playSound(Resource.SOUND_BUTTON, 1);
                 }
                 break;
             case InputKey.POINTER_EVENT_UP:
                 if(canvas.checkButton(x, y, buttBack) && buttBack.getState() == Button.HOLD_CLICK){
                    canvas.setScreen( new Menu(canvas) );
                 }
                 buttBack.setState(Button.ENABLE);
                 break;
         }
    }
    
    public void update() {
        
    }

    public void paint(Graphics g) {

        canvas.getImage().drawImage(g, canvas, Resource.IMG_BG_OTHER, 0, 0);
        buttBack.drawButton(g, canvas);


        g.setFont(CanvasGame.font);
        g.setColor(CanvasGame.BLACK);

        for(int i = 0; i < v.size(); ++i) {
            System.out.println(v.size());
            g.drawString(String.valueOf(i + 1) + ".  ", 20, 105+25*i, Graphics.TOP|Graphics.LEFT);
            g.drawString(((Player)v.elementAt(i)).getName(), 40, 105+25*i, Graphics.TOP|Graphics.LEFT);
            g.drawString(String.valueOf(((Player)v.elementAt(i)).getScore()), 180, 105+25*i, Graphics.TOP|Graphics.LEFT);
        }
    }
}
